﻿<UserControl x:Class="SNAIL.UserControl2"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Height="300" Width="300">

    <UserControl.Resources>
        <Style TargetType="{x:Type TextBox}">
            <Setter Property="BorderThickness" Value="1"/>
            <Setter Property="BorderBrush" Value="LightGray"/>
            <Setter Property="Margin" Value="0 2 0 2"/>
        </Style>

        <Style x:Key="GlowContainer" TargetType="{x:Type ListBoxItem}">
            <Setter Property="FocusVisualStyle">
                <Setter.Value>
                    <Style>
                        <Setter Property="Control.Template">
                            <Setter.Value>
                                <ControlTemplate>
                                    <Border 
                                        Background="Transparent" 
                                        Opacity="0" 
                                        CornerRadius="0">
                                        <Rectangle 
                                            Margin="0" 
                                            StrokeThickness="0" 
                                            Stroke="Transparent" 
                                            StrokeDashArray="1 2"/>
                                    </Border>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </Setter.Value>
            </Setter>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ListBoxItem}">
                        <Border Background="WhiteSmoke"
                                    CornerRadius="5"
                                    BorderThickness="2"
                                    x:Name="ItemBorder"
                                    Margin="6,3,6,3" >
                            <ContentPresenter />
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsSelected" Value="true">
                                <Setter 
                                    TargetName="ItemBorder" 
                                    Property="BitmapEffect">
                                    <Setter.Value>
                                        <OuterGlowBitmapEffect 
                                            GlowColor="Blue" 
                                            GlowSize="5" />
                                    </Setter.Value>
                                </Setter>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </UserControl.Resources>

    <Grid>
        <ListBox 
            x:Name="PersonList" 
            ItemContainerStyle="{StaticResource GlowContainer}" BorderThickness="0">
            <ListBox.Resources>
                <Style TargetType="TextBlock">
                    <Setter Property="FontSize" Value="14"/>
                </Style>
            </ListBox.Resources>
            <ListBox.ItemTemplate>
                <DataTemplate DataType="OutlookPanel.Contact">
                    <Border 
                        Cursor="Hand" 
                        Name="BorderControl" 
                        Background="WhiteSmoke" 
                        BorderThickness="0" 
                        CornerRadius="5" 
                        Padding="5">
                        <StackPanel Orientation="Horizontal">
                            <Border BorderThickness="0" CornerRadius="4">
                                <Image Source="{Binding Path=ContactImagePath}" MaxHeight="40"></Image>
                            </Border>
                            <StackPanel>
                                <TextBlock 
                            Name="TextControl" 
                            Grid.Column="0" 
                            Text="{Binding}" 
                            Background="Transparent" 
                            Padding="4" FontSize="11">
                            <TextBlock.Style>
                                <Style TargetType="TextBlock">
                                    <Style.Triggers>
                                        <DataTrigger 
                                            Binding="{Binding ElementName=BorderControl,Path=IsMouseOver}" 
                                            Value="True">
                                            <Setter Property="Foreground" Value="Black"/>
                                            <Setter Property="FontWeight" Value="Bold"/>
                                        </DataTrigger>
                                        <DataTrigger 
                                            Binding="{Binding 
                          RelativeSource=
                          {
                             RelativeSource 
                             Mode=FindAncestor, 
                             AncestorType={x:Type ListBoxItem}
                          }, 
                          Path=IsSelected
                         }" 
                                            Value="True">
                                            
                                            <Setter Property="Foreground" Value="Black"/>
                                            <Setter Property="FontWeight" Value="Bold"/>
                                        </DataTrigger>
                                    </Style.Triggers>
                                </Style>
                            </TextBlock.Style>
                                </TextBlock>
                                <TextBlock 
                            Name="txtContactInfos" 
                            Grid.Column="0" 
                            Text="{Binding Path=ContactInformation}" 
                            Background="Transparent" 
                            Padding="4" FontSize="11">
                            <TextBlock.Style>
                                <Style TargetType="TextBlock">
                                    <Style.Triggers>
                                        <DataTrigger 
                                            Binding="{Binding ElementName=BorderControl,Path=IsMouseOver}" 
                                            Value="True">
                                            <Setter Property="Foreground" Value="Black"/>
                                            <Setter Property="FontWeight" Value="Bold"/>
                                        </DataTrigger>
                                        <DataTrigger 
                                            Binding="{Binding 
                          RelativeSource=
                          {
                             RelativeSource 
                             Mode=FindAncestor, 
                             AncestorType={x:Type ListBoxItem}
                          }, 
                          Path=IsSelected
                         }" 
                                            Value="True">
                                            
                                            <Setter Property="Foreground" Value="Black"/>
                                            <Setter Property="FontWeight" Value="Bold"/>
                                        </DataTrigger>
                                    </Style.Triggers>
                                </Style>
                            </TextBlock.Style>
                                </TextBlock>
                                <TextBlock 
                            Name="txtExtendedInfos" 
                            Grid.Column="0" 
                            Text="{Binding Path=ExtendedInformation}" 
                            Background="Transparent" 
                            Padding="4" FontSize="11">
                            <TextBlock.Style>
                                <Style TargetType="TextBlock">
                                    <Style.Triggers>
                                        <DataTrigger 
                                            Binding="{Binding 
                          RelativeSource=
                          {
                             RelativeSource 
                             Mode=FindAncestor, 
                             AncestorType={x:Type ListBoxItem}
                          }, 
                          Path=IsSelected
                         }" 
                                            Value="True">
                                             <Setter Property="Visibility" Value="Visible"/>
                                        </DataTrigger>
                                        <DataTrigger 
                                            Binding="{Binding 
                          RelativeSource=
                          {
                             RelativeSource 
                             Mode=FindAncestor, 
                             AncestorType={x:Type ListBoxItem}
                          }, 
                          Path=IsSelected
                         }" 
                                            Value="False">
                                             <Setter Property="Visibility" Value="Collapsed"/>
                                        </DataTrigger>
                                    </Style.Triggers>
                                </Style>
                            </TextBlock.Style>
                                </TextBlock>
                            </StackPanel>
                        </StackPanel>
                    </Border>
                    <DataTemplate.Triggers>
                        <EventTrigger 
                            SourceName="BorderControl" 
                            RoutedEvent="TextBlock.MouseEnter">
                            <BeginStoryboard>
                                <Storyboard>
                                    <ColorAnimation Storyboard.TargetName="BorderControl"    
                                        Storyboard.TargetProperty="Background.Color"   
                                        To="LightBlue" Duration="00:00:00.2" />
                                </Storyboard>
                            </BeginStoryboard>
                        </EventTrigger>
                        <EventTrigger 
                            SourceName="BorderControl" 
                            RoutedEvent="TextBlock.MouseLeave">
                            <BeginStoryboard>
                                <Storyboard>
                                    <ColorAnimation Storyboard.TargetName="BorderControl"    
                                        Storyboard.TargetProperty="Background.Color"   
                                        To="WhiteSmoke" Duration="00:00:00.2" />
                                </Storyboard>
                            </BeginStoryboard>
                        </EventTrigger>
                    </DataTemplate.Triggers>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
    </Grid>
</UserControl>
